import api from '@/api/system'
const state = {
    showUserInfo: false,
    userInfoPanel: 'account',
    showAboutUs: false,
    quikPublish:false,
}

const mutations = {
    CHANGE_SETTING: (state, { key, value }) => {
        // eslint-disable-next-line no-prototype-builtins
        if (state.hasOwnProperty(key)) {
            state[key] = value
        }
    },
}
const actions = {
    changeSetting({ commit }, data) {
        commit('CHANGE_SETTING', data)
    },
    //新增用户角色
    saveRole({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.saveRole(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //删除用户角色
    deleteRole({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.deleteRole(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //删除用户角色
    modifyRole({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.modifyRole(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },

    // 获取角色权限列表
    loadroleList({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.loadroleList(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    // 获取全局用户可分配权限
    loadPermissionResource({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.loadPermissionResource(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },


    //获取用户组信息
    loadUserGroup({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.loadUserGroup(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },

    //查询用户组织信息(用户下级信息)
    loadUserOrg({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.loadUserOrg(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },

    //查询用户组织信息(用户上级信息)
    loadUserUplevel({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.loadUserUplevel(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //查询用户角色权限
    loadUserRoleList({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.loadUserRoleList(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //查询用户下所有组信息()
    loadUserGroupList({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.loadUserGroupList(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //查询用户终端信息
    loadUserDevice({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.loadUserDevice(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //查询用户资源
    loadUserResource({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.loadUserResource(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },

    //查询用户信息(当前组用户列表)
    loadUserList({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.loadUserList(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //新增用户管理分组(当前组用户列表)
    addUserGroup({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.addUserGroup(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //删除用户管理分组(当前组用户列表)
    delUserGroup({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.delUserGroup(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //更新用户管理分组(当前组用户列表)
    updateUserGroup({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.updateUserGroup(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //----------------------用户管理--------------------------------
    //新增用户(当前组用户列表)
    saveUser({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.saveUser(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //更新用户(当前组用户列表)
    updateUser({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.updateUser(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //删除用户
    deleteUser({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.deleteUser(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //用户操作日子
    userOperationLog({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.userOperationLog(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //---------------------系统配置 参数信息
    //获取系统配置 参数信息
    getSystemConfig({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.getSystemConfig(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    //更新系统配置 参数信息
    updateSystemConfig({ commit }, params) {
        return new Promise((resolve, reject) => {
            api.updateSystemConfig(params).then(response => {
                resolve(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}